package com.offcn.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: wy
 * @Date: 2022/9/23 18:13
 */
@Configuration
public class QueueConfig03 {

    private String fanoutExchange01 = "fanoutExchange1";

    private String fanoutExchange02 = "fanoutExchange2";

    //交换机类型 三种 type =   fanout 广播 direct 定向 topic 通配符

    private final String exchange = "exchange";

    /**
     * . 发布者订阅者模式（Publish/Subscribe）
     * 生产者 发送给 交换机  消费者消费 队列
     * 一个生产者 2个或者多个消费者
     *
     * @return
     */
    //@Bean
    public Queue queue1() {
        return new Queue(fanoutExchange01);
    }

    //@Bean
    public Queue queue2() {
        return new Queue(fanoutExchange02);
    }

    /**
     * 声明交换机
     */
    //@Bean
    public FanoutExchange exchange() {
        return new FanoutExchange(exchange);
    }

    //@Bean
    public Binding bind1(Queue queue1, FanoutExchange exchange) {
        return BindingBuilder.bind(queue1).to(exchange);
    }
   // @Bean
    public Binding bind2(Queue queue2, FanoutExchange exchange) {
        return BindingBuilder.bind(queue2).to(exchange);
    }
}
